package com.detroitchow.sqlite;

import com.detroitchow.LogUtil;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class DatabaseHelper extends SQLiteOpenHelper {

  
  private static final String DATABASE_NAME = "detroitchow";
  private static final int DATABASE_VERSION = 1;
  private static final String CREATE_STORES_TABLE = 
    " create table stores ( "+
  "    storeId integer not null primary key, "+
  "    name text not null,  "+
  "    descr text,  "+
  "    address text, "+
  "    city text,  "+
  "    state text,  "+
  "    zipCode text, "+
  "    phone text, "+
  "    lat text, "+
  "    lng text, "+
  "    email text, "+
  "    facebook text, "+
  "    twitter text, "+
  "    google_plus text, "+
  "    website text, "+
  "    short_review text, "+
  "    rank integer , "+
  "		 isListItem integer, "+
  "		 mapGroupId integer, "+
  "		 mapDescr text "+
  " ); ";
  
  private static final String CREATE_TAGS_TABLE = 
    " create table tags ( "+
  "    storeTagId integer not null primary key, "+
  "    storeId integer not null,  "+
  "    tag text); ";

  DatabaseHelper(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
  	  LogUtil.log("DatabaseHelper", "OnCreate");
      db.execSQL(CREATE_STORES_TABLE);
      db.execSQL(CREATE_TAGS_TABLE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
  	LogUtil.log(DatabaseHelper.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS stores");
    db.execSQL("DROP TABLE IF EXISTS tags");
    onCreate(db);
    
  }

}
